# -*- coding: utf-8 -*-
"""
@Time : 2023/9/26 21:06
@Author : ChenXiaoliang
@Email : middlegod@sina.com
@File : find_invalid_pic.py
"""

import os
import logging

LOG_FORMAT = "%(levelname)s %(asctime)s - %(message)s"
logging.basicConfig(filename="invalid_pic.log", level=logging.INFO, format=LOG_FORMAT)
logger = logging.getLogger()

dirs = [_ for _ in os.listdir(".") if _.startswith("[XiuRen秀人网]")]

for directory in dirs:
    # print(directory)
    pics = os.listdir("./" + directory)
    for pic in pics:
        pic_size = os.path.getsize("./" + directory + "/" + pic)
        # 如果图片大小小于500字节
        if pic_size < 500:
            logging.info(f"图片size过小，存在异常 {directory}")
            print("图片size过小，存在异常", directory)
            # 干掉异常图片
            os.remove("./" + directory + "/" + pic)
            break
        # print(type(size))
    # print(len(pics))
    # print(pics)
